package com.mi.soul.windows.DXF;

import com.develop.jawin.COMException;
import com.mi.soul.windows.damo.Idmsoft;
import com.mi.soul.windows.damo.JdmUtil;

import java.io.File;
import java.io.IOException;

/**
 * @Auth yaozhongjie
 * @Date 2019/6/25 11:22
 **/
public class DXF {
    // DXF 设置
    // 窗口模式  垂直同步  16:9  UI设置初始化  UI最大 画质提升关闭
    // 质量全部最低 效果全部关闭 透明度百分比全部为0
    private static final int width = 1280;
    private static final int height = 720;
    private static final String className = "地下城与勇士";
    private static final String titleName = "地下城与勇士";
    private static String PATH_BMP = new File("").getAbsolutePath() + "/src/main/resources/dxf_16_bi_9_1280x720/bmp/";
    private static String PATH_STR = new File("").getAbsolutePath() + "/src/main/resources/dxf_16_bi_9_1280x720/str/";

    public static void main(String[] args) throws COMException, InterruptedException, IOException {
        JdmUtil.setLibPath();
        Idmsoft dm = new Idmsoft("dm.dmsoft");
        System.out.println(dm.Ver());
        int hwnd = dm.FindWindow(className, titleName);
        dm.SetWindowSize(hwnd, width, height);
        dm.BindWindow(hwnd, "dx", "normal", "normal", 1);
//        dm.BindWindow(hwnd, "normal", "normal", "normal", 1);
        dm.SetWindowState(hwnd, 12);
        dm.MoveWindow(hwnd, 0, 0);
        int i = dm.SetDict(0, PATH_STR + "字库.txt");

//        dm.MoveTo(50, 50);
        sleep(3);
//        dm.MoveTo(360, 520);
//        sleep(1);
//        dm.MoveTo(360, 530);
//        sleep(1);
//        dm.MoveTo(360, 520);
//        sleep(1);
//        dm.MoveTo(360, 530);
//        sleep(1);
//        dm.LeftClick();
//        dm.UnBindWindow();
//        sleep(1);
//        dm.MoveTo(570, 15);
//        sleep(1);

        //        sleep(1);

        //找色
//        String s1 = dm.FindColorEx(216,0,325,85,"da2726-000000|f18076-000000|d62325-000000|d87169-000000", 1.0, 0);
//        String[] split = s1.split("\\|");
//        System.out.println("找色 :" +split[0]);
//        System.out.println("找色 :" +split[1]);


        //        找图
//        String i2 = dm.FindPicEx(0, 401, 516, 599, PATH_BMP + "开始冒险.bmp", "000000", 0.9, 0);
//        System.out.println("找图 :" + i2);

        while (true) {
            sleep(0.5);
            String i3 = dm.FindPicEx(0, 0, 587, 720, PATH_BMP + "任务指引_left.bmp", "000000", 0.9, 0);
            System.out.println("任务指引_left :" + i3);
            sleep(0.5);
            String s = dm.FindStrEx(0, 0, 1280, 720, "我去儿童歌", "fefefe-999999", 0.9);
            System.out.println("角色位置 :" + s);
            sleep(0.5);
            String i7 = dm.FindPicEx(0, 0, 587, 720, PATH_BMP + "头盔.bmp", "000000", 0.9, 0);
            System.out.println("头盔 :" + i7);
//            sleep(0.1);
//            String i4 = dm.FindPicEx(0, 0, 1280, 720, PATH_BMP + "指引_top.bmp", "000000", 0.9, 0);
//            System.out.println("指引_top :" + i4);
//
//            sleep(0.1);
//            String i51 = dm.FindPicEx(0, 0, 1280, 720, PATH_BMP + "任务已展开1.bmp", "000000", 0.9, 0);
//            System.out.println("任务已展开1 :" + i51);
//            sleep(0.1);
//            String i52 = dm.FindPicEx(0, 0, 1280, 720, PATH_BMP + "任务已展开2.bmp", "000000", 0.9, 0);
//            System.out.println("任务已展开2 :" + i52);
//
//            sleep(0.1);
//            String i61 = dm.FindPicEx(0, 0, 1280, 720, PATH_BMP + "任务已隐藏1.bmp", "000000", 0.9, 0);
//            System.out.println("任务已隐藏1 :" + i61);
//            sleep(0.1);
//            String i62 = dm.FindPicEx(0, 0, 1280, 720, PATH_BMP + "任务已隐藏2.bmp", "000000", 0.9, 0);
//            System.out.println("任务已隐藏2 :" + i62);
        }

    }

    private static void sleep(Object second) {
        Double v = Double.parseDouble(second.toString()) * 1000;
        try {
            Thread.sleep(v.longValue());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}
